package test.gen.core;

import gen.core.TableFactory;
import gen.core.models.Table;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import junit.framework.TestCase;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

public class TableFactoryTestCase extends TestCase {
	public void testNewTable(){
		final TableFactory aTableFactory = TableFactory.getInstance();
		
		DbUtils.loadDriver("oracle.jdbc.OracleDriver");
		try {

			QueryRunner run = new QueryRunner();

			Properties info = new Properties();

			info.setProperty("user", "bslim");
			info.setProperty("password", "bslim");
			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.25.76.190:1521:erpdvlp", info);
			try {
				ResultSetHandler<Table> h = new ResultSetHandler<Table>() {
					public Table handle(ResultSet rs) throws SQLException {
						return aTableFactory.newTable(rs);
					}
				};

				Table result = run.query(conn, "SELECT * FROM tlitm03", h);
				System.out.println(result);
			} finally {
				DbUtils.close(conn);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
